package com.le.tester.book.effectivejava3rdchinese.articlethirtynine;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * createTime：2022/8/23 14:28
 * description：RunTests
 */
public class RunTests {
    public static void main(String[] args) throws Exception {
        int tests = 0;
        int passed = 0;

        Class<?> testClass = Class.forName(args[0]);
        for (Method m : testClass.getDeclaredMethods()) {
            if (m.isAnnotationPresent(Test.class)) {
                tests = new AtomicInteger(tests).incrementAndGet();
            }
            try {
                m.invoke(null);
                passed = new AtomicInteger(passed).incrementAndGet();
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new RuntimeException();
            }
        }
    }
}
